//
//  vhECGTools.h
//  vhECGTools
//
//  Created by jia yu on 2021/11/19.
//

#import <Foundation/Foundation.h>

FOUNDATION_EXPORT double vhECGToolsVersionNumber;
FOUNDATION_EXPORT const unsigned char vhECGToolsVersionString[];

#ifndef DEFINE_vhECGLead
#define DEFINE_vhECGLead
typedef NS_ENUM(NSInteger, ECGLead) {
    ECGLead_I = 0,
    ECGLead_II = 1,
    ECGLead_III = 2,
    ECGLead_aVR = 3,
    ECGLead_aVL = 4,
    ECGLead_aVF = 5,
    ECGLead_V1 = 6,
    ECGLead_V2 = 7,
    ECGLead_V3 = 8,
    ECGLead_V4 = 9,
    ECGLead_V5 = 10,
    ECGLead_V6 = 11,
    ECGLead_All = 12
};
#endif


#ifndef DEFINE_vhECGAnalisysIndex
#define DEFINE_vhECGAnalisysIndex
typedef NS_ENUM(NSInteger, ECGAnalisysIndex) {
    ECGAnalisysIndex_P_Start = 0,
    ECGAnalisysIndex_P_End = 1,
    ECGAnalisysIndex_QRS_Start = 2,
    ECGAnalisysIndex_QRS_End = 3,
    ECGAnalisysIndex_T_Start = 4,
    ECGAnalisysIndex_T_End = 5
};
#endif

#ifndef DEFINE_vhECGFormat_Style
#define DEFINE_vhECGFormat_Style
typedef NS_ENUM(NSInteger, ECGFormat_Style) {
    ECGFormat_Style_12x1 = 0,
    ECGFormat_Style_6x2 = 1,
    ECGFormat_Style_3x4 = 2,
    ECGFormat_Style_limb_leads = 3      //6x1
};
#endif

typedef NS_OPTIONS(NSUInteger, UISettingHeightUnit) {
    UISettingHeightUnit_AUTO = 0,
    UISettingHeightUnit_FT = 2,
    UISettingHeightUnit_METER = 3
};

typedef NS_OPTIONS(NSUInteger, UISettingWeightUnit) {
    UISettingWeightUnit_AUTO = 0,
    UISettingWeightUnit_LB = 2,
    UISettingWeightUnit_KG = 3
};

typedef NS_OPTIONS(NSUInteger, UISettingSpeedUnit) {
    UISettingSpeedUnit_KmPerH = 2,
    UISettingSpeedUnit_MilePerH = 3
};

typedef NS_OPTIONS(NSUInteger, UISettingSTUnit) {
    UISettingSTUnit_MM = 2,
    UISettingSTUnit_MV = 3
};


typedef NS_OPTIONS(NSUInteger, UISettingPowerUnit) {
    UISettingPowerUnit_W = 2,
    UISettingPowerUnit_Unknow = 3
};

typedef NS_OPTIONS(NSUInteger, UISettingBPUnit) {
    UISettingBPUnit_MMHG = 2,
    UISettingBPUnit_KPA = 3
};

#ifndef DEFINE_REPORT_STATIC
#define DEFINE_REPORT_STATIC
static float PixPermm300DPI = 11.811f;
static float A4LongSide = 3413.5f;
static float A4ShortSide = 2267.4f;
#endif

#import <vhECGTools/vhECGPath.h>

#import <vhECGTools/UIECGBackgroundView.h>
#import <vhECGTools/UIECGRecordingView.h>
#import <vhECGTools/UIECGSingleReView.h>
#import <vhECGTools/UIECGReView.h>
#import <vhECGTools/UIECGReviewLocationView.h>

#import <vhECGTools/UIECGSettingsView.h>


#import <vhECGTools/UIStandardInputTextField.h>
#import <vhECGTools/UIStandardInputTextView.h>
#import <vhECGTools/UIStandardPageControlView.h>
#import <vhECGTools/UIStandardLabel.h>
#import <vhECGTools/UIStandardNameValueLabel.h>
#import <vhECGTools/UIStandardNameInputLabel.h>
#import <vhECGTools/UIStandardSTControlView.h>
#import <vhECGTools/UIStandardArrowLabel.h>
#import <vhECGTools/UIStandardRadioSelectButton.h>
#import <vhECGTools/UIStandardCheckBoxButton.h>
#import <vhECGTools/UIStandardSelectButton.h>
#import <vhECGTools/NSItemObject.h>
#import <vhECGTools/UIStandardBlockView.h>
#import <vhECGTools/UIStandardEditTableView.h>
#import <vhECGTools/UIStandardButton.h>
#import <vhECGTools/UIStandardBirthdayView.h>
#import <vhECGTools/UIStandardRateControlButton.h>

@interface vhECGTools : NSObject

//return AC by currentLocale
+(NSInteger)acInRegion;

//滤波函数
// return 返回值
// value 当前值
// 已经存在的数值数组
// 滤波级别， 级别数字越大，返回数值变化越小。
+(float)filterAveValue:(float)value existValues:(NSArray <NSNumber *>* _Nullable )exists level:(NSUInteger)level;

//HR 专用滤波
+(float)filterHRValue:(float)value existValues:(NSArray <NSNumber *>* _Nullable )exists;

//返回将会打印的ECG时长
//paperWidth 纸张宽度，单位mm
//xRate 纸速 25mm/s 50mm/s 12.5mm/s
//style include ST only in ECGFormat_Style_12x1
+(float)printECGSecondsPaperWidth:(float)paperWidth withXRate:(float)xRate style:(ECGFormat_Style)style;

+ (UIImage * _Nullable )createImageWithColor:(UIColor * _Nonnull )color size:(CGSize)size;

+(void)disableScreenSleep;
+(void)enableScreenSleep;


+(void)alertWith:(NSString * _Nonnull )message;

//返回年龄， if (nil == atDate) that mean now.
+(NSInteger)ageWithBirthday:(NSDate * _Nonnull )birthday at:(NSDate * _Nullable )atDate;

+(CGPoint)middlePointA:(CGPoint)a pointB:(CGPoint)b;

+(UIImage * _Nonnull )scaleImage:(UIImage * _Nonnull )fromImage to:(CGSize)targetSize;

#pragma mark - About Views and Colors
//return current ViewController
+(UIViewController * _Nonnull)currentRootVC;
+(UIColor * _Nullable)colorFromHEXStringwithR:(NSString * _Nonnull)r
                                            G:(NSString * _Nonnull)g
                                            B:(NSString * _Nonnull)b;
+(UIColor * _Nullable)colorFromHEXString:(NSString * _Nonnull)rgb;
+(UIColor * _Nullable)colorFromHEXString:(NSString * _Nonnull)rgb withAlpha:(float)alpha;


#pragma mark - About ECG
+(NSString * _Nullable)leadName:(ECGLead)lead;

//return compressed Data for input ECGs.
//ECGs must have 12 groups for every lead.
//Maximum point is 13200 every lead.
//Every lead's number count must same.
+(NSData * _Nullable )ecg_compress:(NSArray <NSArray <NSNumber *>*>* _Nonnull )ecg_array_array;

//Uncompress ECGs from NSData.
//Return nil when Uncompress failed.
+(NSArray <NSArray <NSNumber *>*>* _Nullable )ecg_uncompress:(NSData * _Nonnull)compressedData;

//Convert ECGs to NSData.
/*
 ECGs include 12 lead, and points in every lead.
 Every lead's point num must samed.
 the swapECG len must more than lead's point * 8
 */
+(NSData * _Nullable)converyECGFromECGs:(NSArray <NSArray <NSNumber *>*>* _Nonnull)ECGs swap:(short * _Nonnull)swapECG swapLen:(int)swapLen;

//Convert ECGs from NSData
/*
 Return ECGs include 12 leads, and points in every lead.
 */
+(NSArray <NSArray <NSNumber *>*>* _Nullable )convertECGFromData:(void * _Nonnull)short_data withLen:(size_t)loadSize;
    
#pragma mark - ST value with Color
+(UIColor * _Nullable)colorWithST:(float)st;
+(UIColor * _Nullable)colorWithLight:(float)wavelength;


#pragma mark - About METs
+(float)METwithTreanmillSpeed:(float)treanmillSpeed withtreanmillSlope:(float)treanillSlope;
+(float)METwithErgometerPower:(float)power withPatientBodyWeight:(float)weight;

//return Power as 踏车。 用跑台的速度和坡度，折算为踏车的功率
+(float)powerBySpeed:(float)speed slope:(float)slope withBodyWeight:(float)weight;

//return RampAuto Expected Power(W)
//bodyWeight is kg
//bodyHeight is cm
+(int)expectedPowerWithGenderMale:(BOOL)isMale age:(int)age weight:(float)bodyWeight height:(float)bodyHeight;
@end


